#!/usr/bin/env bash

###############################################################################
# Copyright (c) 2017, 2022 Red Hat Inc and others
#
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
###############################################################################

#
# This script configures Kapua to make use of SSO using Keycloak
#

set -e

# Commons

. "${BASH_SOURCE%/*}/env"
. "${BASH_SOURCE%/*}/functions"

# Input parameters

# Set Keycloak URL with Kapua

KAPUA_CONSOLE_URL="$(kapua_url)"
KEYCLOAK_URL="$(keycloak_url)"

echo "Configure Kapua for SSO:"
echo "	Kapua Console URL: ${KAPUA_CONSOLE_URL}"
echo "	Keycloack URL:     ${KEYCLOAK_URL}"

$OC set env -n "${KAPUA_PROJECT_NAME}" \
   dc/kapua-console \
   "KEYCLOAK_URL=${KEYCLOAK_URL}" \
   "KAPUA_CONSOLE_URL=${KAPUA_CONSOLE_URL}" \
   ${KEYCLOAK_CLIENT_SECRET:+KEYCLOAK_CLIENT_SECRET=${KEYCLOAK_CLIENT_SECRET}}
